//
//  LzwStartOverPageVC.m
//  NewHalfsugar
//
//  Created by 刘志武 on 16/1/10.
//  Copyright © 2016年 刘志武. All rights reserved.
//

#import "LzwStartOverPageVC.h"
#import "LzwBaseImageView.h"


@interface LzwStartOverPageVC ()<UIScrollViewDelegate>

@property (nonatomic, retain) LzwBaseImageView *myImageView1;
@property (nonatomic, retain) LzwBaseImageView *myImageView2;
@property (nonatomic, retain) LzwBaseImageView *myImageView3;
@property (nonatomic, retain) LzwBaseImageView *myImageView4;

@property (nonatomic, retain) UIScrollView *myScroller;

@end

@implementation LzwStartOverPageVC

-(void)dealloc{
    
    [_myImageView1 release];
    [_myImageView2 release];
    [_myImageView3 release];
    [_myImageView4 release];
    [super dealloc];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.myScroller = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    self.myScroller.contentSize = CGSizeMake(4 * 375 * WIDTH, 667 * WIDTH);
    self.myScroller.pagingEnabled = YES;
    self.myScroller.bounces = NO;
    self.myScroller.delegate = self;
    self.myScroller.showsHorizontalScrollIndicator = NO;

    [self.view addSubview:self.myScroller];
    
    //页码控件
    UIPageControl *pageC = [[UIPageControl alloc]initWithFrame:CGRectMake((375-200)/2 * WIDTH, 667-50 * WIDTH, 200 * WIDTH, 50 * WIDTH)];
    //设置页码个数
    pageC.numberOfPages = 4;
    [self.view addSubview:pageC];
    //设置当前选中的页码颜色
    pageC.currentPageIndicatorTintColor = [UIColor whiteColor];
    //设置其他页码颜色
    pageC.pageIndicatorTintColor = [UIColor lightGrayColor];
    
    //设置当前显示的页码是多少 (放在什么地方？)
    pageC.currentPage = 0;
    pageC.tag = 1000;
    //    UIPageControl核心方法
    [pageC addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    
    

    self.myImageView1 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(0, 0, 375 * WIDTH, 667 * WIDTH)];
    self.myImageView1.image = [UIImage imageNamed:@"11111.png"];
    [self.myScroller addSubview:self.myImageView1];
    
    
    self.myImageView2 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(375 * WIDTH, 0, 375 * WIDTH, 667 * WIDTH)];
    self.myImageView2.image = [UIImage imageNamed:@"22222.png"];

    [self.myScroller addSubview:self.myImageView2];
    
    self.myImageView3 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(2 * 375 * WIDTH, 0, 375 * WIDTH, 667 * WIDTH)];
    self.myImageView3.image = [UIImage imageNamed:@"33333.png"];

    [self.myScroller addSubview:self.myImageView3];
    
   
    
    self.myImageView4 = [[LzwBaseImageView alloc]initWithFrame:CGRectMake(3 * 375 * WIDTH, 0, 375 * WIDTH, 667 * WIDTH)];
    self.myImageView4.image = [UIImage imageNamed:@"44444.jpg"];
    self.myImageView4.userInteractionEnabled = YES;
    [self.myScroller addSubview:self.myImageView4];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame = CGRectMake((375- 200) / 2 * WIDTH, 580 * WIDTH, 200 * WIDTH, 30 * WIDTH);
    button.layer.masksToBounds = YES;
    [button setTitle:@"进入应用" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 15 * WIDTH;
    button.backgroundColor = [UIColor whiteColor];
    [self.myImageView4 addSubview:button];
    
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [pageC release];

    
}

//点击button进入应用主页面
- (void)buttonAction:(UIButton *)but{
    
    //取消模态 进入应用
    [self dismissViewControllerAnimated:NO completion:^{
        
        
    }];
    
}

- (void)pageAction:(UIPageControl *)page{
    
    
    [self.myScroller setContentOffset:CGPointMake(page.currentPage*375, 0) animated:YES];
    
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    UIPageControl *pag = [self.view viewWithTag:1000];
    pag.currentPage = scrollView.contentOffset.x/375 * WIDTH;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
